home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 June: Reference Library / Dev.CD Jun 00 RL Disk 1.toast / pc / technical documentation / develop / develop issue 23 / develop issue 23 code / projectdrag 1.1b8.sea / ProjectDrag 1.1b8 / Sources / ProjectDrag Sources / SelectFolder.c / SelectFolder.c
Encoding:
C/C++ Source or Header  |  1995-06-30  |  3.4 KB  |  136 lines  |  [TEXT/MPS ]

  1. /* SelectFolder.c: Utility Standard File folder selection routines for ProjectDrag.
  2.  * Copied from Inside Macintosh: Files. Not yet used in ProjectDrag.
  3.  *
  4.  * A set of applets for drag and drop source control by Tim Maroney.
  5.  * See develop, issue 23 for details.
  6.  *
  7.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  8.  * and using the MoreFiles utilities by Jim Luther.
  9.  *
  10.  * This software is free, but don't modify and redistribute it without
  11.  * changing the status window to indicate your name and your changes!
  12.  */
  13.  
  14. #include <Types.h>
  15. #include <StandardFile.h>
  16. #include <QuickDraw.h>
  17. #include <TextUtils.h>
  18.  
  19.  
  20. Str255 gPrevSelectedName;
  21. Boolean gDirSelectionFlag;
  22.  
  23.  
  24. pascal Boolean MyCustomFileFilter(CInfoPBPtr pb, Ptr myDataPtr)
  25. {
  26. #pragma unused (myDataPtr)
  27.     return (pb->hFileInfo.ioFlAttrib & 0x10) == 0;
  28. }
  29.  
  30. void SetButtonTitle(ControlHandle button, StringPtr name, Rect *buttonRect)
  31. {
  32.     short result, width;
  33.     Str255 title;
  34.     
  35.     BlockMoveData(name, gPrevSelectedName, name[0] + 1);
  36.     width = (buttonRect->left - buttonRect->right)
  37.             - (StringWidth("Select \"\"") + CharWidth(' '));
  38.     result = TruncString(width, name, smTruncMiddle);
  39.     title[0] = 0;
  40.     AppendString(title, "Select \"");
  41.     AppendString(title, name);
  42.     AppendString(title, "\"");
  43.     SetCTitle(button, title);
  44.     ValidRect(buttonRect);
  45. }
  46.  
  47. #define kGetDirBTN 10
  48.  
  49. pascal short MyDlgHook(short item, DialogPtr theDialog, Ptr myDataPtr)
  50. {
  51.     short myType;
  52.     Handle myHandle;
  53.     Rect myRect;
  54.     Str255 myName;
  55.     CInfoPBRec myPB;
  56.     StandardFileReply *mySFRPtr;
  57.     OSErr myErr;
  58.     short myReturnValue = item;
  59.     
  60.     if (GetWRefCon(theDialog) != sfMainDialogRefCon)
  61.         return myReturnValue;
  62.     
  63.     GetDItem(theDialog, kGetDirBTN, &myType, &myHandle, &myRect);
  64.     if (item == sfHookFirstCall)
  65.     {
  66.         myPB.hFileInfo.ioNamePtr = myName;
  67.         myPB.hFileInfo.ioVRefNum = -LMGetSFSaveDisk();
  68.         myPB.hFileInfo.ioFDirIndex = -1;
  69.         myPB.hFileInfo.ioDirID = LMGetCurDirStore();
  70.         err = PBGetCatInfoSync(&myPB);
  71.         SetButtonTitle((ControlHandle)myHandle, myName, &myRect);
  72.     }
  73.     else
  74.     {
  75.         mySFRPtr = (StandardFileReply*)myDataPtr;
  76.         if (mySFRPtr->sfIsFolder || mySFRPtr->sfIsVolume)
  77.         {
  78.             BlockMoveData(mySFRPtr->sfFile.name, myName, mySFRPtr->sfFile.name[0] + 1);
  79.         }
  80.         else
  81.         {
  82.             myPB.hFileInfo.ioNamePtr = myName;
  83.             myPB.hFileInfo.ioVRefNum = mySFRPtr->sfFile.vRefNum;
  84.             myPB.hFileInfo.ioFDirIndex = -1;
  85.             myPB.hFileInfo.ioDrDirID = mySFRPtr->sfFile.parID;
  86.             myErr = PBGetCatInfoSync(&myPB);
  87.             if (!EqualString(myName, gPrevSelectedName, true, true))
  88.                 SetButtonTitle((ControlHandle)myHandle, myName, &myRect);
  89.             switch (item)
  90.             {
  91.             case kGetDirBTN:
  92.                 myReturnValue = sfItemCancelButton;
  93.                 break;
  94.             case sfItemCancelButton:
  95.                 gDirSelectionFlag = false;
  96.             }
  97.         }
  98.     }
  99.     
  100.     return myReturnValue;
  101. }
  102.  
  103. #define rGetDirectoryDLOG 128
  104.  
  105. StandardFileReply DoGetDirectory(void)
  106. {
  107.     StandardFileReply myReply;
  108.     Point myPoint;
  109.     
  110.     gPrevSelectedName[0] = 0;
  111.     gDirSelectionFlag = true;
  112.     myPoint.h = myPoint.v = -1;
  113.     
  114.     CustomGetFile(myCustomFileFilter, -1, NULL, &myReply, rGetDirectoryDLOG,
  115.                     &myPoint, myDlgHook, NULL, NULL, NULL, &myReply);
  116.     
  117.     if (gDirSelectionFlag)
  118.     {
  119.         myReply.sfFile.name[0] = 0;
  120.         if (myReply.sfIsVolume)
  121.         {
  122.             Str255 myName;
  123.             myName[0] = 0;
  124.             AppendString(myName, myReply.sfFile.name);
  125.             AppendString(myName, "\p:");
  126.             AppendString(myReply.sfFile.name, myName);
  127.         }
  128.         else if (gDirSelectionFlag)
  129.         {
  130.             AppendString(myReply.sfFile.name, gPrevSelectedName);
  131.         }
  132.     }
  133.     myReply.sfValid = gDirSelectionFlag;
  134.     return myReply;
  135. }
  136.